package org.example;

import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;

/**
 * @author shichunyue
 * @date 2025-11-12 16:06
 */
// 关键注解，开启多态类型识别
@JsonTypeInfo(
        use = JsonTypeInfo.Id.NAME,        // 使用名称作为类型标识符
        include = JsonTypeInfo.As.PROPERTY, // 将类型标识符作为JSON的一个属性
        property = "type"                  // 指定JSON中用于存储类型信息的属性名，例如 "type": "sports"
)
@JsonSubTypes({
        @JsonSubTypes.Type(value = PlayPingPong.class, name = "pingpong"),     // 当"type"为"sports"时，创建SportsHobby实例
        @JsonSubTypes.Type(value = PlayComputer.class, name = "computer")  // 当"type"为"computer"时，创建ComputerHobby实例
})
public abstract class Hobby {

    private String hobbyName;
    private String hobbyDesc;

    public Hobby() {
    }

    public Hobby(String hobbyName, String hobbyDesc) {
        this.hobbyName = hobbyName;
        this.hobbyDesc = hobbyDesc;
    }

    public String getHobbyName() {
        return hobbyName;
    }

    public void setHobbyName(String hobbyName) {
        this.hobbyName = hobbyName;
    }

    public String getHobbyDesc() {
        return hobbyDesc;
    }

    public void setHobbyDesc(String hobbyDesc) {
        this.hobbyDesc = hobbyDesc;
    }
}
